<?php
namespace app\admin\model;

use think\Db;
use think\Exception;
class RoomUser 
{
    public function getstatusById($user_id,$room_id)
    {
        try {
            $res=Db::table("zx_room_user")->field('status')->where('user_id',$user_id)->where('room_id',$room_id)
            ->find();
            if(isset($res)){
                return $res['status'];
            }else {
                return 'false';
            }
        }catch (Exception $e){
            print $e->getMessage();
        }
    }
    public function getroomidById($user_id)
    {
        try {
            $res=Db::table("zx_room_user")->field('room_id')->where('user_id',$user_id)
            ->find();
            if(isset($res)){
                return $res;
            }else {
                throw  new Exception("fecth failed");
            }
        }catch (Exception $e){
            print $e->getMessage();
        }
    }
    
    public function update_status($user_id)
    {
    try 
    {  
        
    }catch (Exception $e)
    {
        
    }
    }
    public function add_room_user($room_id,$user_id)
    {
       try { 
           $data=array('room_id'=>$room_id,'user_id'=>$user_id,'status'=>'0');
           $id=Db::table('zx_room_user')->insertGetId($data);
           if($id){
               return 'sucess';
           }else {
               return "failed";
           }
       }catch (Exception $e){
           print $e->getMessage();
       }
    }
}